<?php

function conecta(){
	$host = 'localhost';
	$user = 'root';
	$pass = '';
	$link = mysql_connect($host,$user,$pass);
	if( !mysql_select_db('flash_xml',$link) )
		die("erro: ".mysql_error());
	return $link;		 
}

function geraTicket(){
	$link = conecta();
	$query = mysql_query("SELECT valor FROM imagem",$link);
	$ticket = rand('999999','9999999');
	if( mysql_num_rows($query) > 0 ){
		do{
			$ok = false;		
			mysql_data_seek($query,0);
			while( $row = mysql_fetch_row($query) )
				if( $row[0] == $ticket ){
					$ticket = rand('999999','9999999');
					$ok = true;
				}
		}while($ok);
	}
	return $ticket;
}

function debug($valor){
	$handle = fopen("outputFlash.txt", "w");
	
	if( is_array($valor) ){
		fwrite($handle, "Array (\r\n");
		$i=0;
		foreach($array as $key => $value)
			fwrite($handle, "[".$i++."] ".$key." => ".$value."\r\n");
		fwrite($handle, ")");	
	}
	else
		fwrite($handle, $valor."\r\n");	

}

?>